#include <iostream>
#include <bits/stdc++.h>
using namespace std;

typedef struct {
	int preid;
	int id;
	int value;	
}memory;

memory mr[1000000];

int write(int id, int l, int r, int x) {
	int i;
	for (i=l; i<=r; i++) {
		if (mr[i].id == id || mr[i].id == 0) {
			mr[i].value = x;
			mr[i].id = id;
		}
		else 
			break;
	}
	if (i == l)
		return -1;
	else
		return i-1;
}

int delect(int id, int l, int r) {
	int i;
	for (i=l; i<=r; i++) {
		if (mr[i].id == id) 
			continue;
		else 
			break;
	}
	if (i > r) {
		for (i=l; i<=r; i++) {
			mr[i].id = 0;
			mr[i].preid = id; 
		}
		return 1;
	}
	else 
		return 0;
}

int restore(int id, int l, int r) {
	int i;
	for (i=l; i<=r; i++) {
		if (mr[i].id == 0 && mr[i].preid == id) 
			continue;
		else 
			break;
	}
	if (i > r) {
		for (i=l; i<=r; i++) {
			mr[i].id = id;
		}
		return 1;
	}
	else 
		return 0;
}

int read(int p) {
	if (mr[p].id == p) 
		return 1;
	else 
		return 0;
}


int main() {
	int m, n, k;
	cin >> m >> n >> k;
	
	for (int i=0; i<k; i++) {
		int pro;
		cin >> pro;
		if (pro == 0) {
			int id, l, r, x;
			cin >> id >> l >> r >> x;
			cout << write(id, l, r, x) << endl;
		}
		
		if (pro == 1) {
			int id, l, r;
			cin >> id >> l >> r;
			if (delect(id, l, r)) {
				cout << "OK" << endl;
			}
			else {
				cout << "FAIL" << endl;
			}
		}
		
		if (pro == 2) {
			int id, l, r;
			cin >> id >> l >> r;
			if (restore(id, l, r)) {
				cout << "OK" << endl;
			}
			else {
				cout << "FAIL" << endl;
			}
		}
		
		if (pro == 3) {
			int p;
			cin >> p;
			if (read(p)) {
				cout << mr[p].id << ' ' << mr[p].value <<endl;
			}
			else {
				cout << 0 << " " << 0 << endl;
			}
		}
	}
	//system("pause");
	return 0;
}
